package com.wsoft.system.controller;

import com.wsoft.response.ResponseResult;
import com.wsoft.system.dto.TsConfigInfoDto;
import com.wsoft.system.query.config.ConfigInfoMemberQuery;
import com.wsoft.system.query.config.ConfigInfoOrgQuery;
import com.wsoft.system.query.config.PersonConfigInfoQuery;
import com.wsoft.system.query.config.TsConfigInfoQuery;
import com.wsoft.system.service.ITsConfigInfoService;
import io.swagger.v3.oas.annotations.Operation;
import io.swagger.v3.oas.annotations.tags.Tag;
import org.springframework.web.bind.annotation.*;

import javax.annotation.Resource;
import javax.validation.Valid;

/**
 * <p>
 * 个人配置系统信息表 前端控制器
 * </p>
 *
 * @author kyle
 * @since 2024年09月01日 08:52:31
 */
@RestController
@Tag(name = "单位配置")
@RequestMapping("/ts/configInfo")
public class TsConfigInfoController {

    @Resource
    private ITsConfigInfoService tsConfigInfoService;
    @Operation(summary = "新增单位配置",description = "新增单位配置")
    @PostMapping("/insert")
    public ResponseResult insert(@RequestBody @Valid TsConfigInfoDto dto) {
        boolean b = tsConfigInfoService.insert(dto);
        if (b){
            return ResponseResult.success("[sys.msg.success]");
        }
        else {
            return ResponseResult.failed("[sys.msg.failed]");
        }
    }

    @Operation(summary = "编辑单位配置",description = "编辑单位配置")
    @PostMapping("/update")
    public ResponseResult update(@RequestBody @Valid TsConfigInfoDto dto) {
        boolean b = tsConfigInfoService.update(dto);
        if (b){
            return ResponseResult.success("[sys.msg.success]");
        }
        else {
            return ResponseResult.failed("[sys.msg.failed]");
        }
    }

    @Operation(summary = "新增或修改个人配置",description = "新增或修改个人配置")
    @PostMapping("/editConfigInfo")
    public ResponseResult editConfigInfo(@RequestBody @Valid TsConfigInfoQuery query) {
        tsConfigInfoService.insertOrUpdateConfigInfo(query);
        return ResponseResult.success("[sys.msg.success]");
    }

    @Operation(summary = "删除单位配置",description = "删除数据")
    @GetMapping("/delete")
    public ResponseResult delete(@RequestParam("id") Long id) {
        boolean b = tsConfigInfoService.delete(id);
        if (b){
            return ResponseResult.success("[sys.msg.success]");
        }
        else {
            return ResponseResult.failed("[sys.msg.failed]");
        }
    }

    @Operation(summary = "个人配置恢复默认",description = "个人配置恢复默认")
    @GetMapping("/recover")
    public ResponseResult recover(@RequestParam("code") String code) {
        boolean b = tsConfigInfoService.recover(code);
        if (b){
            return ResponseResult.success("[sys.msg.success]");
        }
        else {
            return ResponseResult.failed("[sys.msg.failed]");
        }
    }
    @Operation(summary = "个人配置恢复默认",description = "个人配置恢复默认")
    @GetMapping("/recoverAll")
    public ResponseResult recover() {
        boolean b = tsConfigInfoService.recoverAll();
        if (b){
            return ResponseResult.success("[sys.msg.success]");
        }
        else {
            return ResponseResult.failed("[sys.msg.failed]");
        }
    }
    @Operation(summary = "查看单位配置详情",description = "查看单位配置详情")
    @GetMapping("/get")
    public ResponseResult getConfigInfo(@RequestParam("id") Long id) {
        return ResponseResult.success(tsConfigInfoService.getConfigInfo(id));
    }

    @Operation(summary = "根据code查看单位配置详情",description = "根据code查看单位配置详情")
    @GetMapping("/getDetail")
    public ResponseResult getDetail(@RequestParam("code") String code) {
        return ResponseResult.success(tsConfigInfoService.getDetail(code));
    }

    @Operation(summary = "根据组织获取单位配置",description = "根据组织获取单位配置详情")
    @PostMapping("/getConfigInfoByOrg")
    public ResponseResult getConfigInfoByOrg(@RequestBody @Valid ConfigInfoOrgQuery query) {
        return ResponseResult.success(tsConfigInfoService.getConfigInfoByOrg(query));
    }

    @Operation(summary = "根据人员获取个人配置",description = "根据人员获取个人配置")
    @PostMapping("/getConfigInfoByMember")
    public ResponseResult getConfigInfoByMember(@RequestBody @Valid ConfigInfoMemberQuery query) {
        return ResponseResult.success(tsConfigInfoService.getConfigInfoByMember(query));
    }

    @Operation(summary = "根据登录人员获取个人配置",description = "根据人员获取个人配置")
    @PostMapping("/getConfigurableByMember")
        public ResponseResult getConfigurableByMember(@RequestBody @Valid PersonConfigInfoQuery query) {
            return ResponseResult.success(tsConfigInfoService.getConfigurableByMember(query));
    }
}

